const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const { merge } = require('webpack-merge')
const common = require('./webpack.common')
const config = require('./config')

module.exports = merge(common, {
  mode: 'development',
  output: {
    path: path.resolve(__dirname, config.dev.dist),
    filename: '[id]_[hash:8].js',
  },
  devtool: 'cheap-module-eval-source-map',
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ['vue-style-loader', 'css-loader'],
      },
      {
        test: /\.less$/,
        use: ['vue-style-loader', 'css-loader', 'less-loader'],
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, `${config.dev.assets}/index.html`),
      title: 'hello vue',
      filename: path.resolve(__dirname, `${config.dev.dist}/index.html`),
    }),
    new webpack.DefinePlugin({
      BASE_URL: JSON.stringify('./'),
    }),
    new webpack.HotModuleReplacementPlugin(),
  ],
  devServer: {
    contentBase: config.dev.assets || './public',
    open: true,
    hotOnly: true,
    port: config.dev.port || 8080,
    proxy: config.dev.proxy,
  },
})
